#!/bin/csh
#-----------------------------------------------------------------------
# DOTESTS TESTS ALL PRECONDITIONERS ON TEST CODES IN BOTH GRIDS AND 
# GENERAL. OUTPUT FILES IN  GENERAL_out and GRIDS_out in TESTS/OUTPUTS
# YS. DEC. 10, 2002 
#-----------------------------------------------------------------------
# begin by setting some parameters.
# part_name : partitioner to be used. The standard one used is dse. 
#  other choices: metis or parmetis. For these make  sure to have
#  the codes compiled properly with the metis or parmetis libraries
#  before attempting to run  DOTESTS.
# np = number of processors. 
# machine : if  'AIX' then poe is used -- for all other
#  machines mpirun is called 
#  currently set automatically using uname
#-----------------------------------------------------------------------  
set np=2 
set part_name=dse  
set machine=`uname -s`
#
if ( ${#argv} < 1 ) then
 set todo=all
else
 set todo=$1
endif
#
if  ($todo != 'grids' && $todo != 'general' && $todo != 'all' ) then
 echo " Incorrect agrument: Usage: %DOTESTS [general | grids | all]"
 exit
endif
##

echo -n '***** Testing ' $todo ' *****\n'

if ( ! (-d OUTPUTS) ) then
  echo ' examples/OUTPUTS directory is created .....' 
  mkdir OUTPUTS
endif
echo ' Results will be written in the ./OUTPUTS directory'
#
if ( $machine != AIX ) then
  echo ' --->  Make sure you have correct hostfiles in GRIDS and GENERAL.\n Please, edit the file named "hostfile".' 
  while (1)
    echo -n ' Proceed with testing [yes/no]? '
    set ans = $<
    switch ($ans)
       case no: 
          exit
       case yes: 
          break 
       default
          continue
   endsw
  end
endif
echo ' --->  checking whether to make library' 

#
(cd .. ; make) 
#

###--->>>GENERAL 
if ($todo == 'all' || $todo == 'general') then
echo ' ---> make executables  in examples/general ' 
cd general

echo '  -------------------- CREATING dd-HB-dse.ex ' 
make dd-HB-dse.ex 

if ( $part_name == metis ) then
echo '  -------------------- CREATING dd-HB-metis.ex ' 
make dd-HB-metis.ex  
endif

if ( $part_name == parmetis ) then
echo '  -------------------- CREATING dd-HB-parmetis.ex ' 
make dd-HB-parmetis.ex  
endif

echo '  -------------------- DONE ' 
cd ..
endif 
##end GENERAL 

###--->>>GRIDS
if ($todo == 'all' || $todo == 'grids') then
echo ' --> make executables  in example/grids ...' 

cd grid

echo '  -------------------- CREATING dd-grid.ex '  
make dd-grid.ex  
cd ..
endif 
##end GRIDS 

##=======================================================================
#                  END compiling/linking - begin running                =
##======================================================================= 

###--->>>GENERAL
if ($todo == 'all' || $todo == 'general') then
echo -------------------------------------------------------------------
echo ' ** running DOTESTS on general. '
echo ' **         Partitioner:' $part_name  ' Machine: ' $machine 
echo -------------------------------------------------------------------

cd general 

#cat extras/inputs > inputs 

if (-f temp) then 
  'rm' temp
endif

echo '   ' > temp
echo ' TEST programs in examples/general' >> temp
echo '   ' >> temp 

set count=0
foreach meth1 (' BJ ' ' RAS ' ' SCHUR ')
foreach meth2 (' ILU0 ' ' ILUK ' ' ILUT ' ' ARMS ' 'ARMS-ddPQ') 
echo ' ----------------------------------------------------------------' >>temp
echo ' --------------------' $meth1 'with' $meth2 '--------------------'>>temp 
echo ' ----------------------------------------------------------------' >>temp
#
# 
#echo '------------------->>' $meth1 'with' $meth2 
@ count++ 

set infile=inputs
#
if($meth2 == ARMS-ddPQ) then
 echo $meth1'         global preconditioner' >! inputs0
 echo 'ARMS           local preconditioner' >> inputs0
 sed -n '3,5 p' $infile >> inputs0
 echo '1              Nonsymmetric ARMS - ARMS-ddPQ' >> inputs0
 sed -n '7,28 p' $infile >> inputs0
else if($meth2 == ARMS) then
 echo $meth1'         global preconditioner' >! inputs0
 echo $meth2          'local preconditioner' >> inputs0
 sed -n '3,5 p' $infile >> inputs0
 echo '0              Nonsymmetric ARMS - ARMS-ddPQ' >> inputs0
 sed -n '7,28 p' $infile >> inputs0
else
 echo $meth1'         global preconditioner' >! inputs0
 echo $meth2'         local preconditioner' >> inputs0
 sed -n '3,28 p' $infile >> inputs0
endif
# 
echo ' --------------------' $meth1 'with' $meth2 'on' 'dd-HB-dse.ex' 
echo '   ' >> temp 
echo ' -----TEST-PROGRAM  DD-HB-DSE.EX------------------------------' >>temp
if ( $machine == AIX ) then
 poe dd-HB-dse.ex  -procs $np >> temp 
else 
 mpirun -np $np ./dd-HB-dse.ex inputs0 >> temp
# mpirun -np $np -machinefile hostfile dd-HB-dse.ex >> temp
endif
#
end
end
##
## DONE
## 
echo '  -------------------- DONE ' 
'mv' temp ../OUTPUTS/GENERAL_out
cd ..
endif 
#----------------------------------------------------------------------- 
#             RUN TESTS IN GRIDS.
#-----------------------------------------------------------------------

###--->>>GRIDS
if ($todo == 'all' || $todo == 'grids') then

echo -------------------------------------------------------------------
echo ' **         running DOTESTS on GRIDS. ' 
echo ' **         Partitioner:' $part_name  ' Machine: ' $machine 
echo -------------------------------------------------------------------

cd grid

if (-f temp) then 
  'rm' temp
endif

echo '   ' > temp
echo ' TEST programs in examples/grids' >> temp
echo '   ' >> temp 

@ count=0 
foreach meth1 (' BJ ' ' RAS ' ' SCHUR ')
foreach meth2 (' ILU0 ' ' ILUK ' ' ILUT ' ' ARMS ' 'ARMS-ddPQ') 
echo ' ----------------------------------------------------------------' >>temp
echo ' --------------------' $meth1 'with' $meth2 '--------------------'>>temp 
echo ' ----------------------------------------------------------------' >>temp
# 
#echo '------------------->>' $meth 

@ count++ 

set infile=inputs
#
if($meth2 == ARMS-ddPQ) then
 echo $meth1'         global preconditioner' >! inputs0
 echo 'ARMS           local preconditioner' >> inputs0
 sed -n '3,5 p' $infile >> inputs0
 echo '1              Nonsymmetric ARMS - ARMS-ddPQ' >> inputs0
 sed -n '7,30 p' $infile >> inputs0
else if($meth2 == ARMS) then
 echo $meth1'         global preconditioner' >! inputs0
 echo $meth2          'local preconditioner' >> inputs0
 sed -n '3,5 p' $infile >> inputs0
 echo '0              Nonsymmetric ARMS - ARMS-ddPQ' >> inputs0
 sed -n '7,30 p' $infile >> inputs0
else
 echo $meth1'         global preconditioner' >! inputs0
 echo $meth2'         local preconditioner' >> inputs0
 sed -n '3,30 p' $infile >> inputs0
endif
# 
echo '   -----TEST-PROGRAM  dd-grid.ex----------------------------------' >>temp
echo ' --------------------' $meth1 'with' $meth2 'on' 'dd-grid.ex' 
if ( $machine == AIX ) then
 poe dd-grid.ex  -procs $np >> temp 
else 
 mpirun -np $np ./dd-grid.ex inputs0 >> temp
# mpirun -np $np -machinefile hostfile dd-grid.ex >> temp
endif
#
end 
end
##
## DONE
## 
'mv' temp ../OUTPUTS/GRIDS_out
cd ..
endif 
echo ' --> TESTS COMPLETED! ' 

unset machine
unset part_name
unset np 
unset infile
unset count 
unset ans


